home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Graphics / VideoToolbox ƒ / VideoToolboxSources / StringToDateAndSecs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-07  |  1.5 KB  |  49 lines  |  [TEXT/KAHL]

  1. /*
  2. StringToDateAndSecs.c
  3. Reads date such as "6/30/91", loads date structure, and returns secs since 1/1/1904.
  4. Returns NAN if date could not be read.
  5.  
  6.  
  7. HISTORY:
  8. 7/27/91 dgp    wrote it
  9. 8/5/91    dgp    made compatible with MPW C 3.2
  10. 8/24/91    dgp    Made compatible with THINK C 5.0.
  11. 12/13/92 dgp Removed obsolete support for THINK C 4.
  12. 5/28/94 dgp Renamed from "StringToDate" to "StringToDateAndSecs" to avoid
  13. conflict with Apple's new Universal Headers. Thanks to Bob Dougherty 
  14. (wolfgang@cats.ucsc.edu) for reporting the incompatibility.
  15. */
  16. #include "VideoToolbox.h"
  17. #include <Script.h>
  18.  
  19. double StringToDateAndSecs(char *string,DateTimeRec *datePtr);
  20.  
  21. double StringToDateAndSecs(char *string,DateTimeRec *datePtr)
  22. {
  23.     LongDateRec longDate;
  24.     LongDateCvt longSecs;
  25.     double secs;
  26.     static DateCacheRecord theCache;
  27.     static Boolean firstTime=1;
  28.     int error;
  29.     long used;
  30.     
  31.     longDate.ld.era=longDate.ld.year=longDate.ld.month=longDate.ld.day=0;
  32.     longDate.ld.hour=longDate.ld.minute=longDate.ld.second=longDate.ld.dayOfWeek=0;
  33.     if(firstTime){
  34.         InitDateCache(&theCache);
  35.         firstTime=0;
  36.     }
  37.     error=String2Date(string,strlen(string),&theCache,&used,&longDate);
  38.     *datePtr=longDate.od.oldDate;
  39.     if(error)return 0./0.;
  40.     LongDate2Secs(&longDate,(LongDateTime *)&longSecs);
  41.     secs=HiWord(longSecs.hl.lHigh);
  42.     secs*=(double)0x10000;
  43.     secs+=(unsigned)LoWord(longSecs.hl.lHigh);
  44.     secs*=(double)0x10000;
  45.     secs+=(unsigned)HiWord(longSecs.hl.lLow);
  46.     secs*=(double)0x10000;
  47.     secs+=(unsigned)LoWord(longSecs.hl.lLow);
  48.     return secs;
  49. }